#region Imports

using System;
using IEC.ColumnOrdering.SP2007.Application.Domain;
using Microsoft.SharePoint;

#endregion

namespace IEC.ColumnOrdering.SP2007.Application.Services.Concrete
{

    /// <summary>
    /// Provides functionality to convert views.
    /// </summary>
    internal static class ViewConverter
    {

        #region Constants

        #endregion

        #region Methods - Static Member

        /// <summary>
        /// Converts the given SharePoint view collection to a collection of views.
        /// </summary>
        /// <param name="sharepointViewCollection">
        /// The SharePoint view collection to be converted.
        /// </param>
        /// <returns>
        /// The result of converting <paramref name="sharepointViewCollection"/>.
        /// </returns>
        public static ViewCollection Convert(SPViewCollection sharepointViewCollection)
        {
            ViewCollection viewCollection = new ViewCollection();

            foreach (SPView sharepointView in sharepointViewCollection)
            {
                View view = ViewConverter.Convert(sharepointView);

                viewCollection.Add(view);
            }

            return viewCollection;
        }

        /// <summary>
        /// Converts the given SharePoint view to a view.
        /// </summary>
        /// <param name="sharepointView">
        /// The SharePoint view to be converted.
        /// </param>
        /// <returns>
        /// The result of converting <paramref name="sharepointView"/>.
        /// </returns>
        public static View Convert(SPView sharepointView)
        {
            View view = new View();

            // set properties
            view.Id = sharepointView.ID;
            view.Name = sharepointView.Title;
            view.DisplayName = sharepointView.Title;
            view.Url = new Uri(
                sharepointView.ParentList.ParentWeb.Url +
                "/" +
                sharepointView.Url);
                       
            return view;
        }

        #endregion

    }

}
